package com.xiaoye.qbproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoye.qbproject.domain.Area;
import com.xiaoye.qbproject.domain.CountryRegion;
import com.xiaoye.qbproject.mapper.AreaMapper;
import com.xiaoye.qbproject.mapper.CountryRegionMapper;
import com.xiaoye.qbproject.res.AreaDropDownRes;
import com.xiaoye.qbproject.service.AreaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【AREA(区域)】的数据库操作Service实现
 * @createDate 2025-07-14 22:56:16
 */
@Slf4j
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService {
    @Autowired
    private CountryRegionMapper countryRegionMapper;

    /**
     * 获取区域下拉列表,带国家列表信息
     *
     * @return 包含区域信息的列表
     */
    @Override
    public List<AreaDropDownRes> getAreaDropDownList() {
        // 获取所有区域
        List<AreaDropDownRes> areaDropDownRes = baseMapper.getAreas();
        if (CollectionUtils.isEmpty(areaDropDownRes)) {
            log.info("没有查询到区域信息");
            return areaDropDownRes;
        }
        // 获取 区域 关联的所有国家
        areaDropDownRes.forEach(area -> {
            List<CountryRegion> countryRegionList = countryRegionMapper.getAreaCountryRegionList(area.getId());
            area.setCountryRegionList(countryRegionList);
        });

        return areaDropDownRes;
    }
}




